package de.reichelt.fx;

import java.text.SimpleDateFormat;
import java.util.Date;
import javafx.scene.control.DatePicker;

public class FxDateField extends DatePicker {
  private SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
  
  public FxDateField() {
  }
  
  public Date getDate() throws Exception {
    String txt = getEditor().getText();
    return (txt==null||txt.isEmpty())?null:sdf.parse(txt);
  }
  
  public final void setDate(Date value) {
    getEditor().setText((value==null)?null:sdf.format(value));
  }
  
}
